package cn.qicaiwang.open.app.mapper;

import cn.qicaiwang.open.app.entity.LegalDocument;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface LegalDocumentMapper extends BaseMapper<LegalDocument> {

    // 原有方法...

    /**
     * 根据案件编号查询文书列表
     * @param caseNumber 案件编号
     * @return 文书列表
     */
    @Select("SELECT * FROM legal_document WHERE case_number = #{caseNumber} AND status = 1 ORDER BY upload_time DESC")
    List<LegalDocument> selectByCaseNumber(String caseNumber);

    /**
     * 根据文书类型查询文书列表
     * @param documentType 文书类型
     * @return 文书列表
     */
    @Select("SELECT d.*, t.type_name as documentTypeName " +
            "FROM legal_document d " +
            "LEFT JOIN document_type_dict t ON d.document_type = t.type_code " +
            "WHERE d.document_type = #{documentType} AND d.status = 1 " +
            "ORDER BY d.upload_time DESC")
    List<LegalDocument> selectByDocumentType(String documentType);

    /**
     * 获取所有文书类型
     * @return 类型列表
     */
    @Select("SELECT type_code, type_name FROM document_type_dict")
    List<Map<String, String>> selectAllDocumentTypes();
}